package com.zhang.modules.mianShi.controller;

import com.zhang.common.web.respWrapper.Res;
import com.zhang.modules.api.annotation.ApiPermission;
import com.zhang.modules.mianShi.entity.AppSystem;
import com.zhang.modules.mianShi.entity.cmd.appSytem.SystemAddCmd;
import com.zhang.modules.mianShi.entity.cmd.appSytem.SystemEditCmd;
import com.zhang.modules.mianShi.entity.cmd.appSytem.SystemPageCmd;
import com.zhang.modules.mianShi.entity.dto.appSystem.AppSystemDto;
import com.zhang.modules.mianShi.service.IAppSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Api(tags = "系统管理")
@RequestMapping("/api/appSystem")
@ApiPermission("app:appSystem:*")
public class AppSystemController {

    private IAppSystemService service;

    public AppSystemController(IAppSystemService service) {
        this.service = service;
    }

    @ApiOperation("系统列表")
    @ApiPermission("app:system:page")
    @GetMapping("/page")
    public Res page(@Valid SystemPageCmd pageCmd){
        Page<AppSystem> result = service.page(pageCmd);
        return Res.ok(result);
    }


    @ApiOperation("系统列表")
    @ApiPermission("app:system:add")
    @PostMapping("/add")
    public Res add(@RequestBody @Valid SystemAddCmd addCmd){
        service.save(addCmd,AppSystem::new);
        return Res.ok("添加成功");
    }


    @ApiOperation("系统删除")
    @ApiPermission("app:system:delete")
    @GetMapping("/delete")
    public Res delete(@Valid @NotBlank(message = "id不能为空") String id){
        service.deleteLogic(id);
        return Res.ok("删除成功");
    }


    @ApiOperation("系统编辑")
    @ApiPermission("app:system:edit")
    @PostMapping("/edit")
    public Res edit(@RequestBody @Valid SystemEditCmd editCmd){
        service.update(editCmd);
        return Res.ok("更新成功");
    }

    @ApiOperation("系统查询Dto")
    @ApiPermission("app:system:list")
    @GetMapping("/list")
    public Res findAllList(@Valid @NotBlank(message = "id不能为空") String regionId){
        List<AppSystemDto> res = service.findAllList(regionId);
        return Res.ok(res);
    }


}
